package com.api.test.controller;

import org.api.result.R;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class IndexController implements ApplicationContextAware {

    ApplicationContext applicationContext;

    @RequestMapping("/index")
    public Object index() {
        Integer port = applicationContext.getEnvironment().getProperty("server.port", Integer.class);
        return R.ok().set("port", port).setData("name","abc");
    }

    @RequestMapping("/index2")
    public Object index2() {
        return Map.of("code", 400, "msg", "index2");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }
}
